package com.d0330.Z30;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

public class Record1 {
    private String name;
    private int amount;

    public Record1(String name, int amount) {
        this.name = name;
        this.amount = amount;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    @Override
    public String toString() {
        return "姓名:" + name +" "+
                "消费金额:" + amount;
    }

    public static void main(String[] args) {
        String []name={"张三","李四"};
        Random r=new Random();
        List<Record1>mylist1=new ArrayList<>();
        List<Record1>mylist2=new ArrayList<>();
        while((mylist1.size()+mylist2.size())<100){
            String name1=name[r.nextInt(2)];
            int amount=r.nextInt(10000)+500;
            Record1 record1= new Record1(name1, amount);
            if (name1=="张三"){
                mylist1.add(record1);
            }else{
                mylist2.add(record1);
            }
        }
        for (Record1 r1:
             mylist1) {
            System.out.println(r1);
        }
        for (Record1 r2:
             mylist2) {
            System.out.println(r2);
        }
        if (mylist1.size()>mylist2.size()){
            mylist1.sort(new TestCompator());
            Iterator i1=mylist1.iterator();
            System.out.println("消费金额最高："+i1.next());
        }else{
            mylist2.sort(new TestCompator());
            Iterator i2=mylist2.iterator();
            System.out.println("消费金额最高："+i2.next());
        }
    }
}
